It shows how to configure trigger node IO settings of area scan cameras.
9 currentsystem = platform.system()
10 if currentsystem ==
'Windows':
11 sys.path.append(os.path.join(os.getenv(
'MVCAM_COMMON_RUNENV'),
"Samples",
"Python",
"MvImport"))
13 sys.path.append(os.path.join(
"..",
"..",
"MvImport"))
15 from MvCameraControl_class
import *
19 if sys.version_info[0] < 3:
21 input_func = raw_input
29 Safely decode a string from a ctypes character array. 30 Compatible with Python 2.x and 3.x, as well as 32-bit and 64-bit environments. 32 byte_str = memoryview(ctypes_char_array).tobytes()
35 null_index = byte_str.find(b
'\x00')
37 byte_str = byte_str[:null_index]
40 for encoding
in [
'gbk',
'utf-8',
'latin-1']:
42 return byte_str.decode(encoding)
43 except UnicodeDecodeError:
47 return byte_str.decode(
'latin-1', errors=
'replace')
51 stFrameInfo = POINTER(MV_FRAME_OUT_INFO_EX)
52 pData = POINTER(c_ubyte)
53 FrameInfoCallBack =
fun_ctype(
None, pData, stFrameInfo, c_void_p)
56 stFrameInfo = cast(pFrameInfo, POINTER(MV_FRAME_OUT_INFO_EX)).contents
58 print(
"get one frame: Width[%d], Height[%d], nFrameNum[%d]" % (stFrameInfo.nWidth, stFrameInfo.nHeight, stFrameInfo.nFrameNum))
62 if __name__ ==
"__main__":
66 MvCamera.MV_CC_Initialize()
68 SDKVersion = MvCamera.MV_CC_GetSDKVersion()
69 print (
"SDKVersion[0x%x]" % SDKVersion)
71 deviceList = MV_CC_DEVICE_INFO_LIST()
72 tlayerType = (MV_GIGE_DEVICE | MV_USB_DEVICE | MV_GENTL_CAMERALINK_DEVICE
73 | MV_GENTL_CXP_DEVICE | MV_GENTL_XOF_DEVICE)
76 ret = MvCamera.MV_CC_EnumDevices(tlayerType, deviceList)
78 print(
"enum devices fail! ret[0x%x]" % ret)
81 if deviceList.nDeviceNum == 0:
82 print(
"find no device!")
85 print(
"Find %d devices!" % deviceList.nDeviceNum)
87 for i
in range(0, deviceList.nDeviceNum):
88 mvcc_dev_info = cast(deviceList.pDeviceInfo[i], POINTER(MV_CC_DEVICE_INFO)).contents
89 if mvcc_dev_info.nTLayerType == MV_GIGE_DEVICE
or mvcc_dev_info.nTLayerType == MV_GENTL_GIGE_DEVICE:
90 print(
"\ngige device: [%d]" % i)
91 strModeName =
decoding_char(mvcc_dev_info.SpecialInfo.stGigEInfo.chModelName)
92 print(
"device model name: %s" % strModeName)
94 strSerialNumber =
decoding_char(mvcc_dev_info.SpecialInfo.stGigEInfo.chSerialNumber)
95 print(
"device serial number: %s" % strSerialNumber)
97 nip1 = ((mvcc_dev_info.SpecialInfo.stGigEInfo.nCurrentIp & 0xff000000) >> 24)
98 nip2 = ((mvcc_dev_info.SpecialInfo.stGigEInfo.nCurrentIp & 0x00ff0000) >> 16)
99 nip3 = ((mvcc_dev_info.SpecialInfo.stGigEInfo.nCurrentIp & 0x0000ff00) >> 8)
100 nip4 = (mvcc_dev_info.SpecialInfo.stGigEInfo.nCurrentIp & 0x000000ff)
101 print(
"current ip: %d.%d.%d.%d\n" % (nip1, nip2, nip3, nip4))
102 elif mvcc_dev_info.nTLayerType == MV_USB_DEVICE:
103 print(
"\nu3v device: [%d]" % i)
104 strModeName =
decoding_char(mvcc_dev_info.SpecialInfo.stUsb3VInfo.chModelName)
105 print(
"device model name: %s" % strModeName)
107 strSerialNumber =
decoding_char(mvcc_dev_info.SpecialInfo.stUsb3VInfo.chSerialNumber)
108 print(
"device serial number: %s" % strSerialNumber)
109 elif mvcc_dev_info.nTLayerType == MV_GENTL_CAMERALINK_DEVICE:
110 print(
"\nCML device: [%d]" % i)
111 strModeName =
decoding_char(mvcc_dev_info.SpecialInfo.stCMLInfo.chModelName)
112 print(
"device model name: %s" % strModeName)
114 strSerialNumber =
decoding_char(mvcc_dev_info.SpecialInfo.stCMLInfo.chSerialNumber)
115 print(
"device serial number: %s" % strSerialNumber)
116 elif mvcc_dev_info.nTLayerType == MV_GENTL_CXP_DEVICE:
117 print(
"\nCXP device: [%d]" % i)
118 strModeName =
decoding_char(mvcc_dev_info.SpecialInfo.stCXPInfo.chModelName)
119 print(
"device model name: %s" % strModeName)
121 strSerialNumber =
decoding_char(mvcc_dev_info.SpecialInfo.stCXPInfo.chSerialNumber)
122 print(
"device serial number: %s" % strSerialNumber)
123 elif mvcc_dev_info.nTLayerType == MV_GENTL_XOF_DEVICE:
124 print(
"\nXoF device: [%d]" % i)
125 strModeName =
decoding_char(mvcc_dev_info.SpecialInfo.stXoFInfo.chModelName)
126 print(
"device model name: %s" % strModeName)
128 strSerialNumber =
decoding_char(mvcc_dev_info.SpecialInfo.stXoFInfo.chSerialNumber)
129 print(
"device serial number: %s" % strSerialNumber)
131 nConnectionNum =
input_func(
"please input the number of the device to connect:")
133 if int(nConnectionNum) >= deviceList.nDeviceNum:
134 print(
"input error!")
141 stDeviceList = cast(deviceList.pDeviceInfo[int(nConnectionNum)], POINTER(MV_CC_DEVICE_INFO)).contents
143 ret = cam.MV_CC_CreateHandle(stDeviceList)
145 raise Exception(
"create handle fail! ret[0x%x]" % ret)
148 ret = cam.MV_CC_OpenDevice(MV_ACCESS_Exclusive, 0)
150 raise Exception(
"open device fail! ret[0x%x]" % ret)
153 if stDeviceList.nTLayerType == MV_GIGE_DEVICE
or stDeviceList.nTLayerType == MV_GENTL_GIGE_DEVICE:
154 nPacketSize = cam.MV_CC_GetOptimalPacketSize()
155 if int(nPacketSize) > 0:
156 ret = cam.MV_CC_SetIntValue(
"GevSCPSPacketSize", nPacketSize)
158 print(
"Warning: Set Packet Size fail! ret[0x%x]" % ret)
160 print(
"Warning: Get Packet Size fail! ret[0x%x]" % nPacketSize)
163 print(
"Now set IO input...")
165 ret = cam.MV_CC_SetEnumValueByString(
"TriggerMode",
"On")
167 raise Exception(
"set trigger mode on fail! ret[0x%x]" % ret)
170 ret = cam.MV_CC_SetEnumValueByString(
"TriggerSource",
"Line0")
172 raise Exception(
"set trigger source fail! ret[0x%x]" % ret)
175 ret = cam.MV_CC_SetEnumValueByString(
"TriggerActivation",
"RisingEdge")
177 raise Exception(
"set trigger activation fail! ret[0x%x]" % ret)
180 ret = cam.MV_CC_SetFloatValue(
"TriggerDelay", 0)
182 raise Exception(
"set trigger delay fail! ret[0x%x]" % ret)
185 ret = cam.MV_CC_SetBoolValue(
"TriggerCacheEnable",
False)
187 raise Exception(
"set trigger cache enable fail! ret[0x%x]" % ret)
190 ret = cam.MV_CC_SetEnumValueByString(
"LineSelector",
"Line0")
192 raise Exception(
"set line selector fail! ret[0x%x]" % ret)
195 ret = cam.MV_CC_SetIntValueEx(
"LineDebouncerTime", 50)
197 raise Exception(
"set line debouncer time fail! ret[0x%x]" % ret)
200 print(
"Now set IO output...")
202 ret = cam.MV_CC_SetEnumValueByString(
"LineSelector",
"Line1")
204 raise Exception(
"set line selector fail! ret[0x%x]" % ret)
207 ret = cam.MV_CC_SetEnumValueByString(
"LineSource",
"ExposureStartActive")
209 raise Exception(
"set line source fail! ret[0x%x]" % ret)
212 ret = cam.MV_CC_SetBoolValue(
"StrobeEnable",
True)
214 raise Exception(
"set strobe enable fail! ret[0x%x]" % ret)
217 ret = cam.MV_CC_SetIntValueEx(
"StrobeLineDuration", 0)
219 raise Exception(
"set strobe line duration fail! ret[0x%x]" % ret)
222 ret = cam.MV_CC_SetIntValueEx(
"StrobeLineDelay", 0)
224 raise Exception(
"set strobe line delay fail! ret[0x%x]" % ret)
227 ret = cam.MV_CC_SetIntValueEx(
"StrobeLinePreDelay", 0)
229 raise Exception(
"set strobe line pre-delay fail! ret[0x%x]" % ret)
232 ret = cam.MV_CC_RegisterImageCallBackEx(CALL_BACK_FUN,
None)
234 raise Exception(
"register image callback fail! ret[0x%x]" % ret)
237 ret = cam.MV_CC_StartGrabbing()
239 raise Exception(
"start grabbing fail! ret[0x%x]" % ret)
241 print(
"start grabbing success")
243 print (
"press Enter key to stop grabbing.")
247 ret = cam.MV_CC_StopGrabbing()
249 raise Exception(
"stop grabbing fail! ret[0x%x]" % ret)
252 ret = cam.MV_CC_CloseDevice()
254 raise Exception(
"close device fail! ret[0x%x]" % ret)
257 cam.MV_CC_DestroyHandle()
259 except Exception
as e:
261 cam.MV_CC_CloseDevice()
262 cam.MV_CC_DestroyHandle()
265 MvCamera.MV_CC_Finalize()